import 'package:flutter_juwo/common/common_index.dart';
import 'package:flutter/material.dart';
import 'package:flutter_juwo/ui/custom/MySeparator.dart';
import 'package:flutter_juwo/ui/custom/real_rich_text.dart';
import 'package:flutter_juwo/ui/utils/utils.dart';

class Invitation extends StatefulWidget {
  @override
  _InvitationState createState() => _InvitationState();
}

class _InvitationState extends State<Invitation> {
  List datas = [
    {"phoneNum": "138****0000 ", "status": "已完成", "isGm": "奖励已发放"},
    {"phoneNum": "138****0000 ", "status": "已注册", "isGm": "未完成任务"},
    {"phoneNum": "138****0000 ", "status": "已注册", "isGm": "未完成任务"},
    {"phoneNum": "138****0000 ", "status": "已注册", "isGm": "未完成任务"},
    {"phoneNum": "138****0000 ", "status": "已注册", "isGm": "未完成任务"},
    {"phoneNum": "138****0000 ", "status": "已注册", "isGm": "未完成任务"},
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        image: DecorationImage(
          image: AssetImage(Utils.getImgPath("bg_invitation")),
          fit: BoxFit.fill,
        ),
      ),
      child: Scaffold(
        backgroundColor: Color(0x00FFFFFF),
        appBar: UiUtils.appBar(context, "邀请好友"),
        body: Column(
          children: <Widget>[
            Expanded(
              flex: 1,
              child: EasyRefresh(
                  child: ListView(
                    children: <Widget>[
                      Container(
                        margin: EdgeInsets.only(top: ScreenUtil().setWidth(62)),
                        width: ScreenUtil().setWidth(572),
                        height: ScreenUtil().setWidth(70),
                        child: Image.asset(
                          Utils.getImgPath("pic_invitation"),
                        ),
                      ),
                      getTop(),
                      getMiddle()
                    ],
                  )),
            ),
            getBottom()
          ],
        ),
      ),
    );
  }

  getTop() {
    return Container(
      height: ScreenUtil().setWidth(528),
      margin: EdgeInsets.fromLTRB(
          ScreenUtil().setWidth(30),
          ScreenUtil().setWidth(46),
          ScreenUtil().setWidth(30),
          ScreenUtil().setWidth(46)),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(7)),
      child: Column(
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(top: ScreenUtil().setWidth(52)),
            child: Row(
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: Center(
                    child: Stack(
                      alignment: AlignmentDirectional.bottomCenter,
                      children: <Widget>[
                        Image.asset(
                          Utils.getImgPath("bg_num1"),
                          width: ScreenUtil().setWidth(220),
                          height: ScreenUtil().setWidth(182),
                        ),
                      ],
                    ),
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Center(
                    child: Stack(
                      alignment: AlignmentDirectional.bottomCenter,
                      children: <Widget>[
                        Image.asset(
                          Utils.getImgPath("bg_num2"),
                          width: ScreenUtil().setWidth(220),
                          height: ScreenUtil().setWidth(182),
                        ),
                      ],
                    ),
                  ),
                )
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: ScreenUtil().setWidth(40)),
            width: ScreenUtil().setWidth(576),
            height: ScreenUtil().setWidth(84),
            decoration: BoxDecoration(
                image: DecorationImage(
                    image: AssetImage(Utils.getImgPath("bg_invitation_tips")))),
            child: Row(
              children: <Widget>[
                Container(
                  margin: EdgeInsets.only(left: ScreenUtil().setWidth(30)),
                  child: Text(
                    "首单奖励",
                    style: TextStyles.custom(
                        30, Colors.white, Font.PingFangHeavy),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(left: ScreenUtil().setWidth(32)),
                  child: RealRichText([
                    TextSpan(
                        text: "邀请好友成功后，首单奖励：",
                        style: TextStyles.custom(24, Color(0xFFb98350),
                            Font.PingFangHeavy)),
                    TextSpan(
                        text: "0.5",
                        style: TextStyles.custom(24, Color(0xFFFB7D00),
                            Font.PingFangHeavy)),
                    TextSpan(
                        text: "元",
                        style: TextStyles.custom(24, Color(0xFFb98350),
                            Font.PingFangHeavy)),
                  ]),
                ),
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: ScreenUtil().setWidth(36)),
            padding: EdgeInsets.only(
                left: ScreenUtil().setWidth(212),
                top: ScreenUtil().setWidth(18)),
            width: ScreenUtil().setWidth(614),
            height: ScreenUtil().setWidth(100),
            decoration: BoxDecoration(
                image: DecorationImage(
                    fit: BoxFit.fill,
                    image: AssetImage(Utils.getImgPath("bg_button")))),
            child: Text(
              "立即邀请好友",
              style: TextStyles.custom(
                  34, Color(0xFF781200), Font.PingFangMedium),
            ),
          )
        ],
      ),
    );
  }

  getMiddle() {
    return Container(
      height: ScreenUtil().setWidth(366),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(7)),
      margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
          ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0),
      child: Column(
        children: <Widget>[
          Container(
            width: ScreenUtil().setWidth(652),
            height: ScreenUtil().setWidth(70),
            margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(22),
                ScreenUtil().setWidth(14), ScreenUtil().setWidth(22), 0),
            decoration: BoxDecoration(
                color: Color(0xFFfed2b1),
                borderRadius: BorderRadius.circular(7)),
            child: RealRichText([
              TextSpan(
                  text: "已累计邀请",
                  style: TextStyles.custom(
                      28, Color(0XFF222222), Font.PingFangBlod)),
              TextSpan(
                  text: "10",
                  style: TextStyles.custom(
                      28, Color(0XFFFE7D00), Font.PingFangBlod)),
              TextSpan(
                  text: "人，赚取",
                  style: TextStyles.custom(
                      28, Color(0XFF222222), Font.PingFangBlod)),
              TextSpan(
                  text: "300",
                  style: TextStyles.custom(
                      28, Color(0XFFFE7D00), Font.PingFangBlod)),
              TextSpan(
                  text: "奖励金",
                  style: TextStyles.custom(
                      28, Color(0XFF222222), Font.PingFangBlod))
            ]),
            alignment: Alignment.center,
          ),
          Container(
            margin: EdgeInsets.only(top: ScreenUtil().setWidth(32)),
            child: Row(
              children: <Widget>[
                getItem("好友手机号"),
                getItem("状态"),
                getItem("是否得到奖励"),
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: ScreenUtil().setWidth(26)),
            width: ScreenUtil().setWidth(588),
            child: MySeparator(color: Color(0xFFbdbdbd)),
          ),
          Expanded(
            flex: 1,
            child: ListView.builder(
                shrinkWrap: true,
                itemCount: datas.length,
                itemBuilder: (BuildContext context, int index) {
                  return getUserItem(datas[index]);
                }),
          )
        ],
      ),
    );
  }

  getItem(String s) {
    return Expanded(
      flex: 1,
      child: Container(
        alignment: Alignment.center,
        child: Text(
          s,
          style: TextStyles.custom(
              24, Color(0xFFbdbdbd), Font.PingFangMedium),
        ),
      ),
    );
  }

  getUserItem(data) {
    return Container(
      margin: EdgeInsets.only(top: ScreenUtil().setWidth(22)),
      child: Row(
        children: <Widget>[
          Expanded(
            flex: 1,
            child: Container(
              margin: EdgeInsets.only(left: ScreenUtil().setWidth(30)),
              alignment: Alignment.center,
              child: Text(
                data["phoneNum"],
                style: TextStyles.custom(
                    24, Colours.appC1, Font.PingFangMedium),
              ),
            ),
          ),
          Expanded(
            flex: 1,
            child: Container(
              alignment: Alignment.center,
              child: Text(
                data["status"],
                style: TextStyles.custom(
                    24,
                    data["status"] == "已完成" ? Color(0xFF2CB823) : Colours.appC1,
                    Font.PingFangMedium),
              ),
            ),
          ),
          Expanded(
            flex: 1,
            child: Container(
              alignment: Alignment.center,
              child: Text(
                data["isGm"],
                style: TextStyles.custom(
                    24,
                    data["isGm"] == "奖励已发放"
                        ? Color(0xFF2CB823)
                        : Color(0xFFFE7D00),
                    Font.PingFangMedium),
              ),
            ),
          ),
        ],
      ),
    );
  }

  getBottom() {
    return Container(
      margin: EdgeInsets.only(bottom: ScreenUtil().setWidth(34)),
      child: Text(
        "活动解释权归礼遇所有",
        style: TextStyles.custom(24, Color.fromRGBO(255, 255, 255, 0.3),
            Font.PingFangRegular),
      ),
    );
  }
}
